<template>
  <div class="app-container">
    <el-form class="el_search" :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"
             style="display: flex; justify-content: flex-end;">
      <el-form-item label="缴费住户" prop="memberName">
        <el-input
          v-model="queryParams.memberName"
          placeholder="请输入"
          clearable
        />
      </el-form-item>
<!--      <el-form-item label="缴费日期" prop="paymentDate">-->
<!--        <el-input-->
<!--          v-model="queryParams.paymentDate"-->
<!--          placeholder="请输入缴费日期"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="apartmentFeesList" @selection-change="handleSelectionChange">
      <el-table-column label="申报人" align="center" prop="memberName" />
      <el-table-column label="费用类型" align="center" prop="feeType" />
      <el-table-column label="费用金额" align="center" prop="amount" />
      <el-table-column label="所申报日期" align="center" prop="paymentDate" />
      <el-table-column label="创建日期" align="center" prop="createdTime" />
      <el-table-column label="备注" align="center" prop="notes" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >修改</el-button>
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--          >删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改收费信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px"  append-to-body center>
      <el-row>
        <el-form ref="form" :model="form" :rules="rules" label-width="100px">
          <el-col :span="12">
            <el-form-item label="申报人" prop="memberName">
              <el-input v-model="form.memberName" placeholder="" />
            </el-form-item>
            <el-form-item label="费用类型" prop="feeType">
              <el-input v-model="form.feeType" placeholder="请输入费用类型" />
            </el-form-item>
            <el-form-item label="费用金额" prop="amount">
              <el-input v-model="form.amount" placeholder="请输入费用金额" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="所申报日期" prop="paymentDate">
              <el-date-picker
                v-model="form.paymentDate"
                type="datetime"
                format="yyyy-MM-dd HH:mm:ss"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="备注" prop="notes">
              <el-input
                type="textarea"
                placeholder="请输入内容"
                :rows="3"
                v-model="form.notes"
                maxlength="200"
                show-word-limit
              />
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listApartmentFees, getApartmentFees, delApartmentFees, addApartmentFees, updateApartmentFees } from "@/api/business/apartmentFees";
import {listAllElderInfo} from "@/api/business/elderInfo";

export default {
  name: "ApartmentFees",
  data() {
    return {
      elderList:{},
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 收费信息表格数据
      apartmentFeesList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        memberName: null,
        feeType: null,
        amount: null,
        paymentDate: null,
        dueDate: null,
        paymentMethod: null,
        notes: null,
        createUserId: null,
        createdTime: null,
        updateUserId: null,
        updatedTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        memberName: [
          { required: true, message: "申报人不能为空", trigger: "blur" }
        ],
        feeType: [
          { required: true, message: "费用类型不能为空", trigger: "change" }
        ],
        amount: [
          { required: true, message: "费用金额不能为空", trigger: "blur" }
        ],
      },
      user:{},
    };
  },
  created() {
    this.getList();
    this.user = this.$store.state.user;
  },
  methods: {
    /** 查询收费信息列表 */
    getList() {
      this.loading = true;
      listApartmentFees(this.queryParams).then(response => {
        this.apartmentFeesList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        elderId: null,
        feeType: null,
        amount: null,
        paymentDate: null,
        dueDate: null,
        paymentMethod: null,
        notes: null,
        createUserId: null,
        createdTime: null,
        updateUserId: null,
        updatedTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加支出申报信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      getApartmentFees(row.id).then(response=>{
        this.form = response.data;
        this.open = true;
        this.title = "修改查看支出申报信息";
      })

    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            this.form.updateUserId = this.user.userId;
            updateApartmentFees(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            this.form.createUserId = this.user.userId;
            addApartmentFees(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除收费信息编号为"' + ids + '"的数据项？').then(function() {
        return delApartmentFees(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/apartmentFees/export', {
        ...this.queryParams
      }, `apartmentFees_${new Date().getTime()}.xlsx`)
    },
  }
};
</script>
<style>
  .el_search{

  }
</style>
